home *** CD-ROM | disk | FTP | other *** search
/ PC Basics 53 / PC Basics Issue 53.iso / Software / Internet / Invboard.exe / PC Basics 53 / Invboard / upload / sources / Post.php < prev    next >
Encoding:
PHP Script  |  2002-07-29  |  28.9 KB  |  930 lines

  1. <?php
  2.  
  3. /*
  4. +--------------------------------------------------------------------------
  5. |   IBFORUMS v1
  6. |   ========================================
  7. |   by Matthew Mecham and David Baxter
  8. |   (c) 2001,2002 IBForums
  9. |   http://www.ibforums.com
  10. |   ========================================
  11. |   Web: http://www.ibforums.com
  12. |   Email: phpboards@ibforums.com
  13. |   Licence Info: phpib-licence@ibforums.com
  14. +---------------------------------------------------------------------------
  15. |
  16. |   > Post core module
  17. |   > Module written by Matt Mecham
  18. |   > Date started: 14th February 2002
  19. |
  20. |   > Module Version 1.0.0
  21. +--------------------------------------------------------------------------
  22. */
  23.  
  24.  
  25. $idx = new Post;
  26.  
  27. class Post {
  28.  
  29.     var $output    = "";
  30.     var $base_url  = "";
  31.     var $html      = "";
  32.     var $parser    = "";
  33.     var $moderator = array();
  34.     var $forum     = array();
  35.     var $topic     = array();
  36.     var $category  = array();
  37.     var $mem_groups = array();
  38.     var $mem_titles = array();
  39.     var $obj        = array();
  40.     var $email      = "";
  41.     
  42.     /***********************************************************************************/
  43.     //
  44.     // Our constructor, load words, load skin, print the topic listing
  45.     //
  46.     /***********************************************************************************/
  47.     
  48.     function Post() {
  49.     
  50.     
  51.         global $ibforums, $DB, $std, $print, $skin_universal;
  52.         
  53.         require "./Skin/".$ibforums->skin_id."/skin_post.php";
  54.         
  55.         require "./sources/lib/post_parser.php";
  56.         
  57.         $this->parser = new post_parser(1);
  58.         
  59.  
  60.         //--------------------------------------
  61.         // Compile the language file
  62.         //--------------------------------------
  63.         
  64.         $ibforums->lang = $std->load_words($ibforums->lang, 'lang_post', $ibforums->lang_id);
  65.  
  66.         $this->html     = new skin_post();
  67.         
  68.         //--------------------------------------
  69.         // Check the input
  70.         //--------------------------------------
  71.         
  72.         if ($ibforums->input['t'])
  73.         {
  74.             $ibforums->input['t'] = $std->is_number($ibforums->input['t']);
  75.             if (! $ibforums->input['t'] )
  76.             {
  77.                 $std->Error( array( LEVEL => 1, MSG => 'missing_files') );
  78.             }
  79.         }
  80.         
  81.         if ($ibforums->input['p'])
  82.         {
  83.             $ibforums->input['p'] = $std->is_number($ibforums->input['p']);
  84.             if (! $ibforums->input['p'] )
  85.             {
  86.                 $std->Error( array( LEVEL => 1, MSG => 'missing_files') );
  87.             }
  88.         }
  89.         
  90.         $ibforums->input['f'] = $std->is_number($ibforums->input['f']);
  91.         if (! $ibforums->input['f'] )
  92.         {
  93.             $std->Error( array( LEVEL => 1, MSG => 'missing_files') );
  94.         }
  95.         
  96.         $ibforums->input['st'] = $ibforums->input['st'] ? $std->is_number($ibforums->input['st']) : 0;
  97.         
  98.         // Did the user press the "preview" button?
  99.         
  100.         $this->obj['preview_post'] = $ibforums->input['preview'];
  101.         
  102.         
  103.         //--------------------------------------
  104.         // Get the forum info based on the forum ID, get the category name, ID, and get the topic details
  105.         //--------------------------------------
  106.         
  107.         $DB->query("SELECT f.*, c.id as cat_id, c.name as cat_name from ibf_forums f, ibf_categories c WHERE f.id=".$ibforums->input[f]." and c.id=f.category");
  108.         
  109.         $this->forum = $DB->fetch_row();
  110.         
  111.         if ($this->forum['read_perms'] != '*')
  112.         {
  113.             if (! preg_match("/(^|,)".$ibforums->member['mgroup']."(,|$)/", $this->forum['read_perms'] ) )
  114.             {
  115.                 $std->Error( array( LEVEL => 1, MSG => 'no_view_topic') );
  116.             }
  117.         
  118.         }
  119.         
  120.         // Is this forum switched off?
  121.         
  122.         if ( ! $this->forum['status'] )
  123.         {
  124.             $std->Error( array( LEVEL => 1, MSG => 'forum_read_only') );
  125.         }
  126.         
  127.         //--------------------------------------
  128.         // Is this a password protected forum?
  129.         //--------------------------------------
  130.         
  131.         $pass = 0;
  132.         
  133.         if ($this->forum['password'] != "")
  134.         {
  135.             if ( ! $c_pass = $std->my_getcookie('iBForum'.$this->forum['id']) )
  136.             {
  137.                 $pass = 0;
  138.             }
  139.         
  140.             if ( $c_pass == $this->forum['password'] )
  141.             {
  142.                 $pass = 1;
  143.             }
  144.             else
  145.             {
  146.                 $pass = 0;
  147.             }
  148.         }
  149.         else
  150.         {
  151.             $pass = 1;
  152.         }
  153.         
  154.         if ($pass == 0)
  155.         {
  156.             $std->Error( array( LEVEL => 1, MSG => 'no_view_topic') );
  157.         }
  158.         
  159.         //--------------------------------------
  160.         
  161.         if ($this->forum['parent_id'] > 0)
  162.         {
  163.         
  164.             $DB->query("SELECT f.id as forum_id, f.name as forum_name, c.id, c.name FROM ibf_forums f, ibf_categories c WHERE f.id='".$this->forum['parent_id']."' AND c.id=f.category");
  165.             
  166.             $row = $DB->fetch_row();
  167.             
  168.             $this->forum['cat_id']   = $row['id'];
  169.             $this->forum['cat_name'] = $row['name'];
  170.             
  171.         }
  172.         
  173.         
  174.         //--------------------------------------
  175.         // Error out if we can not find the forum
  176.         //--------------------------------------
  177.         
  178.         if (!$this->forum['id'])
  179.         {
  180.             $std->Error( array( LEVEL => 1, MSG => 'missing_files') );
  181.         }
  182.         
  183.         $this->base_url = "{$ibforums->vars['board_url']}/index.{$ibforums->vars['php_ext']}?s={$ibforums->session_id}";
  184.         
  185.         //--------------------------------------
  186.         // Is this forum moderated?
  187.         //--------------------------------------
  188.         
  189.         $this->obj['moderate'] = $this->forum['preview_posts'] ? 1 : 0;
  190.         // Can we bypass it?
  191.         if ($ibforums->member['g_avoid_q'])
  192.         {
  193.             $this->obj['moderate'] = 0;
  194.         }
  195.         
  196.         //--------------------------------------
  197.         // Are we allowed to post at all?
  198.         //--------------------------------------
  199.         
  200.         if ($ibforums->member['id'])
  201.         {
  202.             if (!$ibforums->member['allow_post'])
  203.             {
  204.                 $std->Error( array( LEVEL => 1, MSG => 'posting_off') );
  205.             }
  206.             
  207.             // Flood check..
  208.             
  209.             if ( $ibforums->input['CODE'] != "08" and $ibforums->input['CODE'] != "09" )
  210.             {
  211.                 if ( $ibforums->vars['flood_control'] > 0 )
  212.                 {
  213.                     if ($ibforums->member['g_avoid_flood'] != 1)
  214.                     {
  215.                         if ( time() - $ibforums->member['last_post'] < $ibforums->vars['flood_control'] )
  216.                         {
  217.                             $std->Error( array( 'LEVEL' => 1, 'MSG' => 'flood_control' , 'EXTRA' => $ibforums->vars['flood_control'] ) );
  218.                         }
  219.                     }
  220.                 }
  221.                 
  222.             }
  223.             
  224.         }
  225.         
  226.         if ($ibforums->member['id'] != 0 and $ibforums->member['g_is_supmod'] == 0)
  227.         {
  228.             $DB->query("SELECT * from ibf_moderators WHERE member_id='".$ibforums->member['id']."' AND forum_id='".$this->forum['id']."'");
  229.             $this->moderator = $DB->fetch_row();
  230.         }
  231.         
  232.         //--------------------------------------
  233.         // Convert the code ID's into something
  234.         // use mere mortals can understand....
  235.         //--------------------------------------
  236.         
  237.         $this->obj['action_codes'] = array ( '00'  => array( '0'  , 'new_post'     ),
  238.                                              '01'  => array( '1'  , 'new_post'     ),
  239.                                              '02'  => array( '0'  , 'reply_post'   ),
  240.                                              '03'  => array( '1'  , 'reply_post'   ),
  241.                                              '06'  => array( '0'  , 'q_reply_post' ),
  242.                                              '07'  => array( '1'  , 'q_reply_post' ),
  243.                                              '08'  => array( '0'  , 'edit_post'    ),
  244.                                              '09'  => array( '1'  , 'edit_post'    ),
  245.                                              '10'  => array( '0'  , 'poll'         ),
  246.                                              '11'  => array( '1'  , 'poll'         ),
  247.                                            );
  248.                                            
  249.         // Make sure our input CODE element is legal.
  250.         
  251.         if (! isset($this->obj['action_codes'][ $ibforums->input['CODE'] ]) )
  252.         {
  253.             $std->Error( array( LEVEL => 1, MSG => 'missing_files') );
  254.         }
  255.         
  256.         // Require and run our associated library file for this action.
  257.         // this imports an extended class for this Post class.
  258.         
  259.         require "./sources/lib/post_" . $this->obj['action_codes'][ $ibforums->input['CODE'] ][1] . ".php";
  260.         
  261.         $post_functions = new post_functions(&$this);
  262.         
  263.         // If the first CODE array bit is set to "0" - show the relevant form.
  264.         // If it's set to "1" process the input.
  265.         
  266.         // We pass a reference to this classes object so we can manipulate this classes
  267.         // data from our sub class.
  268.         
  269.         if ($this->obj['action_codes'][ $ibforums->input['CODE'] ][0])
  270.         {
  271.             // Make sure we have a "Guest" Name..
  272.             
  273.             if (!$ibforums->member['id'])
  274.             {
  275.             
  276.                 $ibforums->input['UserName'] = trim($ibforums->input['UserName']);
  277.                 $ibforums->input['UserName'] = str_replace( "<br>", "", $ibforums->input['UserName']);
  278.                 $ibforums->input['UserName'] = $ibforums->input['UserName'] ? $ibforums->input['UserName'] : 'Guest';
  279.                 
  280.                 if ($ibforums->input['UserName'] != 'Guest')
  281.                 {
  282.                     $DB->query("SELECT id FROM ibf_members WHERE LOWER(name)='".trim(strtolower($ibforums->input['UserName']))."'");
  283.                     
  284.                     if ( $DB->get_num_rows() )
  285.                     {
  286.                         $ibforums->input['UserName'] = $ibforums->vars['guest_name_pre'].$ibforums->input['UserName'].$ibforums->vars['guest_name_suf'];
  287.                     }
  288.                 }
  289.                 
  290.             }
  291.             
  292.             //-------------------------------------------------------------------------
  293.             // Stop the user hitting the submit button in the hope that multiple topics
  294.             // or replies will be added. Or if the user accidently hits the button
  295.             // twice.
  296.             //-------------------------------------------------------------------------
  297.             
  298.             if ( $this->obj['preview_post'] == "" )
  299.             {
  300.             
  301.                 if ( preg_match( "/Post,.*,(01|03|07|11)$/", $ibforums->location ) )
  302.                 {
  303.                     if ( time() - $ibforums->lastclick < 2 )
  304.                     {
  305.                         if ( $ibforums->input['CODE'] == '01' or $ibforums->input['CODE'] == '11' )
  306.                         {
  307.                             // Redirect to the newest topic in the forum
  308.                             
  309.                             
  310.                             $DB->query("SELECT tid from ibf_topics WHERE forum_id='".$this->forum['id']."' AND approved=1 "
  311.                                       ."ORDER BY last_post DESC LIMIT 0,1");
  312.                                       
  313.                             $topic = $DB->fetch_row();
  314.                     
  315.                             $std->boink_it($ibforums->base_url."&act=ST&f=".$this->forum['id']."&t=".$topic['tid']);
  316.                             exit();
  317.                         }
  318.                         else
  319.                         {
  320.                             // It's a reply, so simply show the topic...
  321.                             
  322.                             $std->boink_it($ibforums->base_url."&act=ST&f=".$this->forum['id']."&t=".$ibforums->input['t']."&view=getlastpost");
  323.                             exit();
  324.                         }
  325.                     }
  326.                 }
  327.             
  328.             }
  329.             
  330.             //----------------------------------
  331.        
  332.             $post_functions->process(&$this);
  333.         }
  334.         else
  335.         {
  336.             $post_functions->show_form(&$this);
  337.         }
  338.         
  339.         
  340.  
  341.     }
  342.     
  343.     /*****************************************************/
  344.     // topic tracker
  345.     // ------------------
  346.     // Checks and sends out the emails as needed.
  347.     /*****************************************************/
  348.     
  349.     function topic_tracker($tid="", $post="", $poster="")
  350.     {
  351.         global $ibforums, $DB, $std;
  352.         
  353.         require "./sources/lib/emailer.php";
  354.         
  355.         $this->email = new emailer();
  356.         
  357.         //--------------------------
  358.     
  359.         if ($tid == "")
  360.         {
  361.             return TRUE;
  362.         }
  363.     
  364.         // Configure the date
  365.         $getdate = time() - (60*60*24);
  366.         
  367.         // Get the email addy's, topic ids and email_full stuff - oh yeah.
  368.         
  369.         $DB->query("SELECT tr.trid, tr.topic_id, m.name, m.email, m.id, m.email_full, m.language, t.title, t.forum_id FROM ibf_tracker tr, ibf_topics t,ibf_members m WHERE tr.topic_id='$tid' AND tr.member_id=m.id AND t.tid=tr.topic_id AND (tr.last_sent < '$getdate' or tr.last_sent=0)");
  370.         
  371.         if (  $DB->get_num_rows() )
  372.         {
  373.             $trids = array();
  374.             
  375.             while ( $r = $DB->fetch_row() )
  376.             {
  377.             
  378.                 $r['language'] = $r['language'] ? $r['language'] : 'en';
  379.                 
  380.                 // We don't want to be notified of our own posts, so..
  381.                 
  382.                 if ($r['id'] == $ibforums->member['id'])
  383.                 {
  384.                     continue;
  385.                 }
  386.                 
  387.                 //-----------------------------------------------------
  388.                 
  389.                 if ($r['email_full'] == 1)
  390.                 {
  391.                 
  392.                     $this->email->get_template("subs_with_post", $r['language']);
  393.             
  394.                     $this->email->build_message( array(
  395.                                                         'TOPIC_ID'        => $r['topic_id'],
  396.                                                         'FORUM_ID'        => $r['forum_id'],
  397.                                                         'TITLE'           => $r['title'],
  398.                                                         'NAME'            => $r['name'],
  399.                                                         'POSTER'          => $poster,
  400.                                                         'POST'            => $post,
  401.                                                       )
  402.                                                 );
  403.                                                 
  404.                     $this->email->subject = $ibforums->lang['tt_subject'];
  405.                     $this->email->to      = $r['email'];
  406.                     $this->email->send_mail();
  407.                     
  408.                 }
  409.                 else
  410.                 {
  411.                 
  412.                     $this->email->get_template("subs_no_post", $r['language']);
  413.             
  414.                     $this->email->build_message( array(
  415.                                                         'TOPIC_ID'        => $r['topic_id'],
  416.                                                         'FORUM_ID'        => $r['forum_id'],
  417.                                                         'TITLE'           => $r['title'],
  418.                                                         'NAME'            => $r['name'],
  419.                                                         'POSTER'          => $poster,
  420.                                                       )
  421.                                                 );
  422.                                                 
  423.                     $this->email->subject = $ibforums->lang['tt_subject'];
  424.                     $this->email->to      = $r['email'];
  425.                     
  426.                     $this->email->send_mail();
  427.                     
  428.                 }
  429.                 
  430.                 $trids[] = $r['trid'];
  431.             }
  432.             
  433.             // Update the DB wid' da new time, innit.
  434.             
  435.             $trid_string = implode( ",", $trids );
  436.             
  437.             if ( count($trids) > 0 )
  438.             {
  439.             
  440.                 $DB->query("UPDATE ibf_tracker SET last_sent='".time()."' WHERE trid IN(".$trid_string.")");
  441.             }
  442.             
  443.         }
  444.         
  445.         return TRUE;
  446.         
  447.     }
  448.     
  449.     /*****************************************************/
  450.     // compile post
  451.     // ------------------
  452.     // Compiles all the incoming information into an array
  453.     // which is returned to the accessor
  454.     /*****************************************************/
  455.     
  456.     function compile_post() {
  457.         global $ibforums, $std, $REQUEST_METHOD, $HTTP_POST_VARS;
  458.         
  459.         $ibforums->vars['max_post_length'] = $ibforums->vars['max_post_length'] ? $ibforums->vars['max_post_length'] : 2140000;
  460.         
  461.         // sort out some of the form data, check for posting length, etc.
  462.         // THIS MUST BE CALLED BEFORE CHECKING ATTACHMENTS
  463.         
  464.         $ibforums->input['enablesig'] = $ibforums->input['enablesig'] == 'yes' ? 1 : 0;
  465.         $ibforums->input['enableemo'] = $ibforums->input['enableemo'] == 'yes' ? 1 : 0;
  466.         
  467.         // Do we have a valid post?
  468.         
  469.         if (strlen( trim($HTTP_POST_VARS['Post']) ) < 1) {
  470.             $std->Error( array( LEVEL => 1, MSG => 'no_post') );
  471.         }
  472.         
  473.         if (strlen( $HTTP_POST_VARS['Post'] ) > ($ibforums->vars['max_post_length']*1024)) {
  474.             $std->Error( array( LEVEL => 1, MSG => 'post_too_long') );
  475.         }
  476.         
  477.         $post = array(
  478.                         'author_id'   => $ibforums->member['id'] ? $ibforums->member['id'] : 0,
  479.                         'use_sig'     => $ibforums->input['enablesig'],
  480.                         'use_emo'     => $ibforums->input['enableemo'],
  481.                         'ip_address'  => $ibforums->input['IP_ADDRESS'],
  482.                         'post_date'   => time(),
  483.                         'icon_id'     => $ibforums->input['iconid'],
  484.                         'post'        => $this->parser->convert( array( TEXT    => $ibforums->input['Post'],
  485.                                                                         SMILIES => $ibforums->input['enableemo'],
  486.                                                                         CODE    => $this->forum['use_ibc'],
  487.                                                                         HTML    => $this->forum['use_html']
  488.                                                                       )
  489.                                                                ),
  490.                         'author_name' => $ibforums->member['id'] ? $ibforums->member['name'] : $ibforums->input['UserName'],
  491.                         'forum_id'    => $this->forum['id'],
  492.                         'topic_id'    => "",
  493.                         'queued'      => $this->obj['moderate'],
  494.                         'attach_id'   => "",
  495.                         'attach_hits' => "",
  496.                         'attach_type' => "",
  497.                      );
  498.                      
  499.         // If we had any errors, parse them back to this class
  500.         // so we can track them later.
  501.         
  502.         $this->obj['post_errors'] = $this->parser->error;
  503.                      
  504.         return $post;
  505.     }
  506.     
  507.     /*****************************************************/
  508.     // process upload
  509.     // ------------------
  510.     // checks for an entry in the upload field, and uploads
  511.     // the file if it meets our criteria. This also inserts
  512.     // a new row into the attachments database if successful
  513.     /*****************************************************/
  514.     
  515.     function process_upload() {
  516.     
  517.         global $ibforums, $std, $HTTP_POST_FILES, $DB, $FILE_UPLOAD;
  518.         
  519.         //-------------------------------------------------
  520.         // Set up some variables to stop carpals developing
  521.         //-------------------------------------------------
  522.         
  523.         $FILE_NAME = $HTTP_POST_FILES['FILE_UPLOAD']['name'];
  524.         $FILE_SIZE = $HTTP_POST_FILES['FILE_UPLOAD']['size'];
  525.         $FILE_TYPE = $HTTP_POST_FILES['FILE_UPLOAD']['type'];
  526.         
  527.         // Naughty Opera adds the filename on the end of the
  528.         // mime type - we don't want this.
  529.         
  530.         $FILE_TYPE = preg_replace( "/^(.+?);.*$/", "\\1", $FILE_TYPE );
  531.         
  532.         $attach_data = array( 'attach_id'   => "",
  533.                               'attach_hits' => "",
  534.                               'attach_type' => "",
  535.                               'attach_file' => "",
  536.                             );
  537.                             
  538.         //-------------------------------------------------                    
  539.         // Return if we don't have a file to upload
  540.         //-------------------------------------------------
  541.         
  542.         // Naughty Mozilla likes to use "none" to indicate an empty upload field.
  543.         // I love universal languages that aren't universal.
  544.         
  545.         if ($HTTP_POST_FILES['FILE_UPLOAD']['name'] == "" or !$HTTP_POST_FILES['FILE_UPLOAD']['name'] or ($HTTP_POST_FILES['FILE_UPLOAD']['name'] == "none") ) return $attach_data;
  546.         
  547.         //-------------------------------------------------
  548.         // Return empty handed if we don't have permission to use
  549.         // uploads
  550.         //-------------------------------------------------
  551.         
  552.         if ( (!$this->forum['use_attach']) and ($ibforums->member['g_attach_max'] < 1) ) return $attach_data;
  553.         
  554.         //-------------------------------------------------
  555.         // Load our mime types config file.
  556.         //-------------------------------------------------
  557.         
  558.         require "./conf_mime_types.php";
  559.         
  560.         //-------------------------------------------------
  561.         // Are we allowing this type of file?
  562.         //-------------------------------------------------
  563.         
  564.         if ($mime_types[ $FILE_TYPE ][0] != 1)
  565.         {
  566.             $this->obj['post_errors'] = 'invalid_mime_type';
  567.             return $attach_data;
  568.         }
  569.         
  570.         //-------------------------------------------------
  571.         // Check the file size
  572.         //-------------------------------------------------
  573.         
  574.         if ($FILE_SIZE > ($ibforums->member['g_attach_max']*1024))
  575.         {
  576.             $std->Error( array( LEVEL => 1, MSG => 'upload_to_big') );
  577.         }
  578.         
  579.         //-------------------------------------------------
  580.         // Make the uploaded file safe
  581.         //-------------------------------------------------
  582.         
  583.         $FILE_NAME = preg_replace( "/[^\w\.]/", "_", $FILE_NAME );
  584.         
  585.         $real_file_name = "post-".$this->forum['id']."-".time();  // Note the lack of extension!
  586.         
  587.         if (preg_match( "/\.(cgi|pl|js|asp|php|html|htm|jsp|jar)/", $FILE_NAME ))
  588.         {
  589.             $FILE_TYPE = 'text/plain';
  590.         }
  591.         
  592.         //-------------------------------------------------
  593.         // Add on the extension...
  594.         //-------------------------------------------------
  595.         
  596.         $ext = '.ibf';
  597.         
  598.         switch($FILE_TYPE)
  599.         {
  600.             case 'image/gif':
  601.                 $ext = '.gif';
  602.                 break;
  603.             case 'image/jpeg':
  604.                 $ext = '.jpg';
  605.                 break;
  606.             case 'image/pjpeg':
  607.                 $ext = '.jpg';
  608.                 break;
  609.             case 'image/x-png':
  610.                 $ext = '.png';
  611.                 break;
  612.             default:
  613.                 $ext = '.ibf';
  614.                 break;
  615.         }
  616.         
  617.         $real_file_name .= $ext;
  618.         
  619.         //-------------------------------------------------
  620.         // If we are previewing the post, we don't want to
  621.         // add the attachment to the database, so we return
  622.         // the array with the filename. We would have returned
  623.         // earlier if there was an error
  624.         //-------------------------------------------------
  625.         
  626.         if ($this->obj['preview_post'])
  627.         {
  628.             return array( 'FILE_NAME' => $FILE_NAME );
  629.         }
  630.         
  631.         //-------------------------------------------------
  632.         // Copy the upload to the uploads directory
  633.         //-------------------------------------------------
  634.         
  635.         if (! @move_uploaded_file( $HTTP_POST_FILES['FILE_UPLOAD']['tmp_name'], $ibforums->vars['upload_dir']."/".$real_file_name) )
  636.         {
  637.             $this->obj['post_errors'] = 'upload_failed';
  638.             return $attach_data;
  639.         }
  640.         
  641.         //-------------------------------------------------
  642.         // set the array, and enter the info into the DB
  643.         // We don't have an extension on the file in the
  644.         // hope that it make it more difficult to execute
  645.         // a script on our server.
  646.         //-------------------------------------------------
  647.         
  648.         $attach_data['attach_id']   = $real_file_name;
  649.         $attach_data['attach_hits'] = 0;
  650.         $attach_data['attach_type'] = $FILE_TYPE;
  651.         $attach_data['attach_file'] = $FILE_NAME;
  652.         
  653.         return $attach_data;
  654.     }
  655.  
  656.         
  657.     
  658.     /*****************************************************/
  659.     // check_upload_ability
  660.     // ------------------
  661.     // checks to make sure the requesting browser can accept
  662.     // file uploads, also checks if the member group can
  663.     // accept uploads and returns accordingly.
  664.     /*****************************************************/
  665.     
  666.     function check_upload_ability() {
  667.         global $ibforums;
  668.         
  669.         if ($this->forum['use_attach'] and $ibforums->member['g_attach_max'] > 0)
  670.         {
  671.             $this->obj['can_upload']   = 1;
  672.             $this->obj['form_extra']   = " enctype='multipart/form-data'";
  673.             $this->obj['hidden_field'] = "<input type='hidden' name='MAX_FILE_SIZE' value='".($ibforums->member['g_attach_max']*1024)."'>";
  674.         }
  675.         
  676.     }
  677.     
  678.     /*****************************************************/
  679.     // HTML: mod_options.
  680.     // ------------------
  681.     // Returns the HTML for the mod options drop down box
  682.     /*****************************************************/
  683.     
  684.     function mod_options() {
  685.         global $ibforums, $DB;
  686.         
  687.         $can_close = 0;
  688.         $can_pin   = 0;
  689.         
  690.         $html = "<select id='forminput' name='mod_options' class='forminput'>\n<option value='nowt'>".$ibforums->lang['mod_nowt']."</option>\n";
  691.         
  692.         if ($ibforums->member['g_is_supmod'])
  693.         {
  694.             $can_close = 1;
  695.             $can_pin   = 1;
  696.         }
  697.         else if ($ibforums->member['id'] != 0)
  698.         {
  699.             if ($this->moderator['mid'] != "" )
  700.             {
  701.                 if ($this->moderator['close_topic'])
  702.                 {
  703.                     $can_close = 1;
  704.                 }
  705.                 if ($this->moderator['pin_topic'])
  706.                 {
  707.                     $can_pin   = 1;
  708.                 }
  709.             }
  710.         }
  711.         else
  712.         {
  713.             return "";
  714.         }
  715.         
  716.         if ($can_pin == 0 and $can_close == 0)
  717.         {
  718.             return "";
  719.         }
  720.         
  721.         if ($can_pin)
  722.         {
  723.             $html .= "<option value='pin'>".$ibforums->lang['mod_pin']."</option>";
  724.         }
  725.         if ($can_close)
  726.         {
  727.             $html .= "<option value='close'>".$ibforums->lang['mod_close']."</option>";
  728.         }
  729.         
  730.         return $this->html->mod_options($html);
  731.     
  732.     }
  733.  
  734.     /*****************************************************/
  735.     // HTML: start form.
  736.     // ------------------
  737.     // Returns the HTML for the <FORM> opening tag
  738.     /*****************************************************/
  739.     
  740.     function html_start_form($additional_tags=array()) {
  741.         global $ibforums;
  742.         
  743.         $form = "<form action='{$this->base_url}' method='POST' name='REPLIER' onSubmit='return ValidateForm()'".$this->obj['form_extra'].">".
  744.                 "<input type='hidden' name='st' value='".$ibforums->input[st]."'>".
  745.                 "<input type='hidden' name='act' value='Post'>".
  746.                 "<input type='hidden' name='s' value='".$ibforums->session_id."'>".
  747.                 "<input type='hidden' name='f' value='".$this->forum['id']."'>".
  748.                 $this->obj['hidden_field'];
  749.                 
  750.         // Any other tags to add?
  751.         
  752.         if (isset($additional_tags)) {
  753.             foreach($additional_tags as $k => $v) {
  754.                 $form .= "\n<input type='hidden' name='{$v[0]}' value='{$v[1]}'>";
  755.             }
  756.         }
  757.         
  758.         return $form;
  759.     }
  760.         
  761.     /*****************************************************/
  762.     // HTML: name fields.
  763.     // ------------------
  764.     // Returns the HTML for either text inputs or membername
  765.     // depending if the member is a guest.
  766.     /*****************************************************/
  767.     
  768.     function html_name_field() {
  769.         global $ibforums;
  770.         
  771.         return $ibforums->member['id'] ? $this->html->nameField_reg() : $this->html->nameField_unreg( $ibforums->input[UserName] );
  772.     }
  773.     
  774.     /*****************************************************/
  775.     // HTML: Post body.
  776.     // ------------------
  777.     // Returns the HTML for post area, code buttons and
  778.     // post icons
  779.     /*****************************************************/
  780.     
  781.     function html_post_body($raw_post="") {
  782.         global $ibforums;
  783.         
  784.         $ibforums->lang['the_max_length'] = $ibforums->vars['max_post_length'] * 1024;
  785.         
  786.         return $this->html->postbox_buttons($raw_post);
  787.         
  788.     }
  789.     
  790.     /*****************************************************/
  791.     // HTML: Post Icons
  792.     // ------------------
  793.     // Returns the HTML for post area, code buttons and
  794.     // post icons
  795.     /*****************************************************/
  796.     
  797.     function html_post_icons($post_icon="") {
  798.         global $ibforums;
  799.         
  800.         if ($ibforums->input['iconid'])
  801.         {
  802.             $post_icon = $ibforums->input['iconid'];
  803.         }
  804.         
  805.         $ibforums->lang['the_max_length'] = $ibforums->vars['max_post_length'] * 1024;
  806.         
  807.         $html = $this->html->PostIcons();
  808.         
  809.         if ($post_icon) {
  810.             $html = preg_replace( "/name=[\"']iconid[\"']\s*value=[\"']$post_icon\s?[\"']/", "name='iconid' value='$post_icon' checked", $html );
  811.             $html = preg_replace( "/name=[\"']iconid[\"']\s*value=[\"']0[\"']\s*checked/i"  , "name='iconid' value='0'", $html );
  812.         }
  813.         return $html;
  814.     }
  815.     
  816.     /*****************************************************/
  817.     // HTML: add smilie box.
  818.     // ------------------
  819.     // Inserts the clickable smilies box
  820.     /*****************************************************/
  821.     
  822.     function html_add_smilie_box() {
  823.         global $ibforums, $DB;
  824.         
  825.         $show_table = 0;
  826.         $count      = 0;
  827.         $smilies    = "<tr align='center'>\n";
  828.         
  829.         // Get the smilies from the DB
  830.         
  831.         $DB->query("SELECT * FROM ibf_emoticons WHERE clickable='1'");
  832.         
  833.         while ($elmo = $DB->fetch_row() ) {
  834.         
  835.             $show_table++;
  836.             $count++;
  837.             
  838.             $smilies .= "<td><a href=\"javascript:emoticon('".$elmo['typed']."')\"><img src=\"".$ibforums->vars['EMOTICONS_URL']."/".$elmo['image']."\" alt='smilie' border='0'></a> </td>\n";
  839.             
  840.             if ($count == $ibforums->vars['emo_per_row']) {
  841.                 $smilies .= "</tr>\n\n<tr align='center'>";
  842.                 $count = 0;
  843.             }
  844.         }
  845.         
  846.         if ($count != $ibforums->vars['emo_per_row']) {
  847.             for ($i = $count ; $i < $ibforums->vars['emo_per_row'] ; ++$i) {
  848.                 $smilies .= "<td> </td>\n";
  849.             }
  850.             $smilies .= "</tr>";
  851.         }
  852.         
  853.         $table = $this->html->smilie_table();
  854.         
  855.         if ($show_table != 0) {
  856.             $table = preg_replace( "/<!--THE SMILIES-->/", $smilies, $table );
  857.             $this->output = preg_replace( "/<!--SMILIE TABLE-->/", $table, $this->output );
  858.         }
  859.     
  860.     }
  861.         
  862.     /*****************************************************/
  863.     // HTML: topic summary.
  864.     // ------------------
  865.     // displays the last 10 replies to the topic we're
  866.     // replying in.
  867.     /*****************************************************/
  868.     
  869.     function html_topic_summary($topic_id) {
  870.         
  871.         global $ibforums, $std, $DB;
  872.         
  873.         if (! $topic_id ) return;
  874.         
  875.         $cached_members = array();
  876.         
  877.         $this->output .= $this->html->TopicSummary_top();
  878.         
  879.         //--------------------------------------------------------------
  880.         // Get the posts
  881.         // This section will probably change at some point
  882.         //--------------------------------------------------------------
  883.         
  884.         $post_query = $DB->query("SELECT post, pid, post_date, author_id, author_name FROM ibf_posts WHERE topic_id='$topic_id' and queued <> 1 ORDER BY pid DESC LIMIT 0,10");
  885.         
  886.         while ( $row = $DB->fetch_row($post_query) )
  887.         {
  888.             
  889.             $row['author'] = $row['author_name'];
  890.             
  891.             $row['date']   = $std->get_date( $row['post_date'], 'LONG' );
  892.             
  893.             $this->output .= $this->html->TopicSummary_body( $row );
  894.         }
  895.         
  896.         $this->output .= $this->html->TopicSummary_bottom();
  897.         
  898.     }
  899.     
  900.     /*****************************************************/
  901.     // Moderators log
  902.     // ------------------
  903.     // Simply adds the last action to the mod logs
  904.     /*****************************************************/
  905.     
  906.     function moderate_log($title = 'unknown', $topic_title) {
  907.         global $std, $ibforums, $DB, $HTTP_REFERER, $QUERY_STRING;
  908.         
  909.         $db_string = $std->compile_db_string( array (
  910.                                                         'forum_id'    => $ibforums->input['f'],
  911.                                                         'topic_id'    => $ibforums->input['t'],
  912.                                                         'post_id'     => $ibforums->input['p'],
  913.                                                         'member_id'   => $ibforums->member['id'],
  914.                                                         'member_name' => $ibforums->member['name'],
  915.                                                         'ip_address'  => $ibforums->input['IP_ADDRESS'],
  916.                                                         'http_referer'=> $HTTP_REFERER,
  917.                                                         'ctime'       => time(),
  918.                                                         'topic_title' => $topic_title,
  919.                                                         'action'      => $title,
  920.                                                         'query_string'=> $QUERY_STRING,
  921.                                                     )
  922.                                             );
  923.         
  924.         $DB->query("INSERT INTO ibf_moderator_logs (" .$db_string['FIELD_NAMES']. ") VALUES (". $db_string['FIELD_VALUES'] .")");
  925.         
  926.     }
  927.         
  928. }
  929.  
  930. ?>